'use strict'
class db_wxUserUpload{

    constructor (mdb) {
        this.db = mdb
    }
    

    //微信用户上传app名字和功能名字加图标
    async wxUserUploadFunc(data){

        // let data = {
        //     openid:c.box.user.openid,
        //     appname:c.body.appname,
        //     funcname:c.body.funcname,
        //     imagename:imageName
        // }

        let time = new Date().getTime();


        let sql = `INSERT INTO reviewing(appname,funcname,icon,openid,review,time) VALUES ('${data.appname}','${data.funcname}','${data.imagename}','${data.openid}',0,'${time}') returning id`
        let r = await this.db.query(sql)
        console.log(r.rows[0]);
        let id = r.rows[0].id;
        return id;
    }


    //微信用户上传app步骤
    async wxUserUploadStep(data){

        // let data = {
        //     funcid:c.body.funcid,
        //     stepid:c.body.stepid,
        //     dote1:c.body.dote1,
        //     dote2:c.body.dote2,
        //     text:c.body.text,
        //     imagename:fname
        // }

        let dote3,dote4;

        if(data.dote1 < 15 || data.dote2 < 15){
            dote3 = data.dote1 + 30;
            dote4 = data.dote2 + 30;
        }else{
            dote3 = data.dote1 - 30;
            dote4 = data.dote2 - 30;
        }


        let sql = `INSERT INTO usercreateappfunc (funcid,stepid,dote1,dote2,dote3,dote4,text,img) VALUES (${data.funcid},${data.stepid},${data.dote1},${data.dote2},${dote3},${dote4},'${data.text}','${data.imagename}')`
        let ret = await this.db.query(sql)
        if (ret.rowCount <= 0) {
            return false
        }
        return true;
    }
}

module.exports = db_wxUserUpload